<?php
include("include/conn.php");

if(isset($_GET['vepaariBookMasterId']))
{
	$selectVepaari = "SELECT vepaaribillmaster.vepaariBookDate, vepaaribilldetail.particulars, vepaaribilldetail.fine, vepaaribilldetail.amount, vepaaribilldetail.CrDr, party.partyName
	                    FROM vepaaribillmaster
	                    JOIN vepaaribilldetail 	ON vepaaribilldetail.vepaariBookMasterId = vepaaribillmaster.vepaariBookMasterId
	                    JOIN party ON party.partyId = vepaaribook.partyId
	                   WHERE vepaaribookId = ".$_GET['vepaariBookMasterId']."
	                     AND inRojmel = 1";
	$selectVepaariRes = mysql_query($selectVepaari);
	if($row = mysql_fetch_assoc($selectVepaariRes))
	{
		$insertRojmel = "INSERT INTO rojmel (rojmelDate, particulars, fine, amount, CrDr)
		                 VALUES ('".$row['vepaariBookDate']."','".$row['particulars']." (".$row['partyName'].")',".$row['fine'].",".$row['amount'].",
		                         '".$row['CrDr']."')";
	  $insertRojmelRes = mysql_query($insertRojmel);
	}
	
  $vepaariBook = "DELETE FROM vepaaribillmaster
                   WHERE vepaariBookMasterId = ".$_GET['vepaariBookMasterId'];
  $vepaariBookRes = mysql_query($vepaariBook);
  
  $vepaariBook = "DELETE FROM vepaaribilldetail 
                   WHERE vepaariBookMasterId = ".$_GET['vepaariBookMasterId']; 
  if(isset($_GET['rojmel']))
    header("location:rojmel.php");
  else
    header("location:	.php");
}
else
  header("location:vepaariBookDetail.php");
?>